
const wxAppId = 'wx01df5d24e02b1052';
const wxSecret = '7c6c97bb294c7e05d7dd7e275b0549b8'

module.exports = {

	async getWechatAccess() {
		return await uniCloud.httpclient.request(
			`https://api.weixin.qq.com/cgi-bin/token`, {
				data: {
					grant_type: 'client_credential',
					appid: wxAppId,
					secret: wxSecret
				},
				contentType: 'json',
				dataType: 'json'
			}
		)
	},
	async getWechatPhone(ACCESS_TOKEN, code) {
		return await uniCloud.httpclient.request(
			`https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=${ACCESS_TOKEN}`, {
				method: "POST",
				data: {
					code: code
				},
				contentType: 'json',
				dataType: 'json'
			}
		)
	},
	/**
	 * @param {Object} code 登录code
	 * 微信获取用户openid
	 */
	async getWechatOpenid(js_code) {
		return await uniCloud.httpclient.request(
			"https://api.weixin.qq.com/sns/jscode2session", // 请求路径,
			{
				data: {
					js_code,
					grant_type: 'authorization_code',
					appid: wxAppId,
					secret: wxSecret
				},
				contentType: 'json',
				dataType: 'json'
			}
		)
	},
	/**
	 * @param {Object} code 登录code：通过uni.login获取的code
	 * 头条获取用户openid
	 */
	async getOpenid(code) {
		return await uniCloud.httpclient.request(
			"https://developer.toutiao.com/api/apps/jscode2session", // 请求路径，各端不一致，见官方文档
			{
				data: {
					code,
					appid: "", //头条的appid
					secret: "", //头条的appid的secret
				},
				contentType: 'json',
				dataType: 'json'
			}
		)
	},
	/**
	 * @param {Object} code 登录code：通过uni.login获取的code
	 * 头条获取用户openid
	 */
	async getKuaiShouOpenid(code) {
		return await uniCloud.httpclient.request(
			"https://open.kuaishou.com/oauth2/mp/code2session", // 请求路径，各端不一致，见官方文档
			{
				data: {
					js_code: code,
					app_id: "", //快手的appid
					app_secret: "", //快手的appid的secret
				},
				method: 'POST',
				contentType: 'x-www-form-urlencoded',
				dataType: 'json'
			}
		)
	},
}